< previous page page_418 next page >

Page 418
Continued
Listing 18.1
    sWaitForLetter = ""
    CurrentLetter = ""

    lblLoaded = "Loading the list . . ."
    Set dbBiblio = OpenDatabase("d:\vb6\biblio.mdb")
    DoEvents

    tmrLoad.Enabled = True

End Sub

Function SearchListBox(lstX As Control, KeyAscii As Integer)
    Dim nSearchPos As Integer
    Dim nSearchLen As Integer
    Dim nResult As Integer

    nSearchPos = lstX.ListIndex
    nSearchLen = Len(sLstSearch)
    sWaitForLetter = ""

    'CHECK FOR BACKSPACE KEY
    If KeyAscii = vbKeyBack Then
        nSearchPos = 0
        If nSearchLen > 0 Then sLstSearch = Left$(sLstSearch, nSearchLen - 1)
    End If

    'CAPTIALIZE THE NEW CHARACTER
    KeyAscii = Asc(UCase$(Chr$(KeyAscii)))

    'IF YOU PRESS 'X' AND DATA IS ONLY LOADED TO 'C' THEN WAIT . . .
    If nSearchLen = 0 And KeyAscii > Asc(CurrentLetter) Then
        lstX.ListIndex = lstX.ListCount - 1
        sWaitForLetter = Chr$(KeyAscii)
        DoEvents
        Exit Function
    End If

    'ADD NEW LETTER TO SEARCH STRING
    If KeyAscii >= Asc("A") And KeyAscii <= Asc("Z") Then
       sLstSearch = sLstSearch & Chr$(KeyAscii)
    End If

    'DISPLAY SEARCH STRING
    lblSrchtext = sLstSearch

    'RE-CALCULATE LENGTH
    nSearchLen = Len(sLstSearch)

    'SIMPLE SEARCH - COMPARES EACH ITEM TO SEARCH STRING
    While nSearchPos < lstX.ListCount
        nResult = StrComp(sLstSearch, UCase$(Left$(lstX.List(nSearchPos),_\
 nSearchLen)))
        If nResult <= 0 Then
            lstX.ListIndex = nSearchPos
            SearchListBox = 0
            Exit Function
        End If

 
< previous page page_418 next page >